package cn.kgc.flight.controller;

import cn.kgc.flight.client.RestFlightServiceClient;
import cn.kgc.flight.pojo.City;
import cn.kgc.flight.pojo.Flight;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("flight")
public class FlightController {

    @Resource
    private RestFlightServiceClient flightService;

    @RequestMapping("/showCity")
    public List<City> showCity() {
        return flightService.showAllCity();
    }

    @RequestMapping("/showFlight")
    public List<Flight> showFlight(@RequestParam Integer did, @RequestParam Integer aid) {
        Flight flight = new Flight();
        flight.setDepartureCity(did);
        flight.setArrivalCity(aid);
        return flightService.showFlight(did, aid);
    }

    @RequestMapping("/count")
    public Boolean queryCountByFlightNo(@RequestParam String flightNo) {
        Flight flight = new Flight();
        flight.setFlightNo(flightNo);
        return flightService.queryCountByFlightNo(flightNo);
    }

    @RequestMapping("/add")
    public Boolean addFlight(@RequestBody Flight flight) {
        return flightService.addFlight(flight);
    }

}
